<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
		$result = $this->tmessage__getlist();
		if (!(empty($result['errcode']))) 
		{
			exi($result['errmsg'],'error');
		}
		foreach ($result['template_list'] as $key => &$value ) 
		{	$value['id']=$key;
			preg_match_all('{{(.)*?}}', $value['content'], $matches);
			foreach ($matches[0] as &$v ) 
			{
				$v = str_replace(array('{', '}', '.DATA'), '', $v);
			}
			unset($v);
			$value['contents'] = $matches[0];
			$result['template_list'][$key]['content'] = str_replace(array("\n\n", "\n"), '<br />', $value['content']);
		}
		unset($value);
	$return['list']=$result['template_list'];
if($_RQ['op']=='list'){

	$htmls=array(
			'type'=>'list',
			'tabs'=>array(
				array('op'=>'list','title'=>'微信模板管理'),
				array('op'=>'edit','title'=>'添加模板'),
			),
			'list'=>array('data'=>'list','list'=>array(
				array('name'=>'template_id','title'=>'模板id','type'=>'string'),
				array('name'=>'title','title'=>'模板名称','type'=>'string'),
				array('name'=>'primary_industry','title'=>'模板一级行业','type'=>'string'),
				array('name'=>'deputy_industry','title'=>'模板二级行业','type'=>'string'),
			),
			),
		);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='edit'){
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'模板设置',
		'edit'=>array(
					array('type'=>'string','title'=>'模板编号','name'=>'code'),
					
			),
			);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
		$postdata=get_postdata();		
		$result = $this->tmessage__getid($postdata['code']);
		if (!(is_array($result))){
			exi('添加失败','error','list');
		}
		if (!(empty($result['errcode']))){ 
			exi($result['errcode'],'error','list');
		}
		exi('添加成功','error','list');
			}
if($_RQ['op']=='del'){
		$id=$_RQ['id'];
		$item=$return['list'][$id];
		$result = $this->tmessage__delete($item['template_id']);
		
		if (!(empty($result['errcode']))) 
		{
			exi($result['errmsg'],'error');
		}
		
		exi('删除成功！');
}
?>